package com.huluobo.lib_http

import com.blankj.utilcode.util.SPUtils
import com.tencent.mmkv.MMKV
import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 *  Created by LC on 2025/2/24.
 */
class TokenRetrofitImpl : BaseRetrofitImpl() {
    val mmkv = MMKV.defaultMMKV()
    override fun createRetrofit(): Retrofit {
        return Retrofit.Builder()
            .baseUrl(Const.BASE_URL)
            .client(createHttp().addInterceptor { chain ->
                chain.proceed(
                    chain.request().newBuilder()
                        .addHeader(
                            Const.PARAM_TOKEN,
                            mmkv.decodeString(Const.PARAM_TOKEN, "")!!
                        ).build()
                )
            }.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(FlowCallAdapterFactory.create())
            .build()
    }
}